<!--
 * @Description: 
 * @Author: wgy
 * @CreateTime: 2022-12-17 22:41:18
 * @UpdateTime: 2022-12-17 22:43:25
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 定义一个容器 -->
    <div id="box"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-domm库 用于操作dom -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入babel,用于将jsx转换为js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <script type="text/babel">
        // 创建一个类组件
        class MyComponent extends React.Component {
            // 在实例中创建一个全局状态
            state = { isHost: true, wind: "微风" }

            render() {
                // 读取状态
                const { isHost, wind } = this.state
                return <h1 onClick={this.changeWeather} >今天的天气真是{isHost ? "好热" : "好凉爽"},风向{wind}</h1>
            }

            // 第三方方法写成此形式可以将this指向进行绑定
            changeWeather = () => {
                const { isHost } = this.state
                this.setState({ isHost: !isHost })
            }
        }

        // 渲染元素
        ReactDOM.render(<MyComponent />, document.getElementById("box"))
    </script>
</body>

</html>